package com.winsomely.leecode;

/**
 * 数字的补数
 * 
 * @author liujiawei
 *
 */
public class FindComplement {

	public int findComplement(int num) {
		String bs = Integer.toBinaryString(num);
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < bs.length(); i++) {
			char c = bs.charAt(i);
			builder.append(c == '0' ? "1" : "0");
		}
		return Integer.parseInt(builder.toString(), 2);
	}

	public static void main(String[] args) {
		FindComplement t = new FindComplement();
		System.out.println(t.findComplement(5));
	}

}
